package code;
import java.io.File;
import java.util.HashMap;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;


public class Language {
	public HashMap changeLanguage(String language, String baseFile, String installPath){
		HashMap labels=null;
		
		try{

			labels= new HashMap();
			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   
			DocumentBuilder parser = factory.newDocumentBuilder();
			Document d;
			if(language.equalsIgnoreCase("TUR")){
				d= parser.parse(installPath + File.separator + "xml" + File.separator + baseFile + "_tur.xml");
			} else if(language.equalsIgnoreCase("ENG")) {
				d= parser.parse(installPath + File.separator + "xml" + File.separator + baseFile + "_eng.xml");
			} else {
				// No defined language found. Use default one.
				d= parser.parse(installPath + File.separator + "xml" + File.separator + baseFile + "_eng.xml");
			}


			Element root = d.getDocumentElement();
			Node n = root.getFirstChild();  
			if (n != null){  

				do {   
					if (n.getNodeType() == Node.ELEMENT_NODE){   
						labels.put(n.getNodeName(), n.getFirstChild().getNodeValue());
					}   
				}while ((n=n.getNextSibling()) != null );   
			}   
		}catch(Exception e){
			e.printStackTrace();
		}
		return labels;

	}   

}